From 1d0605bf9a0f936ee3b0808b3195bb7eff920bdd Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 10 Mar 2007 23:36:13 +0000 Subject: [PATCH] Sketch in data structures for multiple URLs in waypoints. Use GDB reader as guinea pig. --- defs.h | 15 ++++++++++++++- gdb.c | 10 +++++++--- util.c | 27 +++++++++++++++++++++++++++ waypt.c | 18 +++++++++++++++++- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/defs.h b/defs.h index 0c8e081a5..3bfb8b31e 100644 --- a/defs.h +++ b/defs.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002, 2003, 2004, 2005 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -276,6 +276,12 @@ typedef struct { unsigned int cet_converted:1; /* strings are converted to UTF8; interesting only for input */ } wp_flags; +typedef struct url_link { + struct url_link *url_next; + char *url; + char *url_link_text; +} url_link; + /* * This is a waypoint, as stored in the GPSR. It tries to not * cater to any specific model or protocol. Anything that needs to @@ -325,6 +331,13 @@ typedef struct { * Few formats support this. */ char *notes; + + /* This is a bit icky. Multiple waypoint support is an + * afterthought and I don't want to change our data structures. + * So we have the first in the waypoint itself and subsequent + * ones in a linked list. + */ + struct url_link *url_next; char *url; char *url_link_text; diff --git a/gdb.c b/gdb.c index e2c23825c..94a439138 100644 --- a/gdb.c +++ b/gdb.c @@ -90,8 +90,8 @@ /* %%% local vars %%% */ -/* static char gdb_release[] = "$Revision: 1.48 $"; */ -static char gdb_release_date[] = "$Date: 2007/02/20 20:51:15 $"; +/* static char gdb_release[] = "$Revision: 1.49 $"; */ +static char gdb_release_date[] = "$Date: 2007/03/10 23:36:14 $"; static FILE *fin, *fout; static char *fin_name, *fout_name; @@ -514,10 +514,14 @@ gdb_read_wpt(const size_t fileofs, int *wptclass) gdb_is_valid((url_ct >= 0), prefix, "Number of urls (since v3)"); while (url_ct > 0) { + char v3xurl[GDB_URL_BUFFERLEN]; url_ct--; - gdb_fread_str(xurl, sizeof(xurl)); /* URL list */ + gdb_fread_str(v3xurl, sizeof(v3xurl)); /* URL list */ + add_url(res, xstrdup(v3xurl), NULL); +#if 0 if ((url == NULL) && (xurl[0] != '\0')) url = xstrdup(xurl); /* keep only the first valid entry */ +#endif } if (url != NULL) { strncpy(xurl, url, sizeof(xurl)); diff --git a/util.c b/util.c index 1af7d25e6..7d32a2eb1 100644 --- a/util.c +++ b/util.c @@ -1641,3 +1641,30 @@ char *get_filename(const char *fname) return (res == NULL) ? (char *) fname : ++res; } + +void +add_url(waypoint *wpt, char *link, char *url_link_text) +{ + /* Special case first one; it goes right into the waypoint. */ + if ((wpt->url == NULL) && (wpt->url_link_text == NULL)) { + wpt->url = link; + wpt->url_link_text = url_link_text; + } else { + url_link *tail; + url_link *new_link = xcalloc(sizeof(url_link), 1); + new_link->url = link; + new_link->url_link_text = url_link_text; + + /* Find current end of chain. */ + for (tail = wpt->url_next;;tail = tail->url_next) { + if (tail == NULL) { + wpt->url_next = new_link; + break; + } + if (tail->url_next == NULL) { + tail->url_next = new_link; + break; + } + } + } +} diff --git a/waypt.c b/waypt.c index f58179c77..da9b98fba 100644 --- a/waypt.c +++ b/waypt.c @@ -1,7 +1,7 @@ /* Perform various operations on waypoints. - Copyright (C) 2002-2005 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002-2007 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -304,6 +304,22 @@ waypt_free( waypoint *wpt ) if (wpt->url_link_text) { xfree(wpt->url_link_text); } + if (wpt->url_next) { + url_link *url_next; + + for (url_next = wpt->url_next; url_next; ) { + + url_link *tonuke = url_next; + if (tonuke->url) { + xfree(tonuke->url); + } + if (tonuke->url_link_text) { + xfree(tonuke->url_link_text); + } + url_next = tonuke->url_next; + xfree(tonuke); + } + } if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic) { xfree((char *)(void *)wpt->icon_descr); } -- 2.30.2